var a = require("../../../../@babel/runtime/helpers/defineProperty"), t = require("../../../../@babel/runtime/helpers/typeof"), e = getApp();

Page({
    data: {
        language: "",
        level_name: "",
        rate: 0,
        ratioDatas: [],
        activeName: "first",
        first_content: [],
        second_content: [],
        third_content: [],
        fourth_content: [],
        dividend: {},
        mailLanguage: "",
        area_dividend_title: "区域代理",
        dividend_amount: "佣金",
        area_dividend: "",
        is_first_content: !1,
        is_second_content: !1,
        is_third_content: !1,
        is_fourth_content: !1,
        page: 1,
        showNone: !1
    },
    onLoad: function(a) {
        this.cheackRouter(), this.getData(), this.initInfo(), this.getAreaDividend(), this.getDividendList("");
        try {
            var t = JSON.parse(wx.getStorageSync("mailLanguage"));
            if (t && t.area_dividend) {
                var e = t.area_dividend.title || "区域代理";
                wx.setNavigationBarTitle({
                    title: e + "中心"
                }), this.setData({
                    area_dividend_title: e
                });
            }
        } catch (a) {}
    },
    cheackRouter: function() {
        try {
            var a = function() {
                for (var a = wx.getStorageSync("yz_basic_info"), t = a.popularize_page.mini.vue_route, e = 0; e < t.length; e++) if ("AgentBonus" == t[e]) return console.log(a.popularize_page.mini.mini_url + "跳转的路径"), 
                wx.showToast({
                    title: "未开启推广权限",
                    duration: 1e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: a.popularize_page.mini.mini_url
                            });
                        }, 1e3);
                    }
                }), {
                    v: void 0
                };
            }();
            if ("object" === t(a)) return a.v;
        } catch (a) {
            console.log(a);
        }
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getAreaDividend: function() {
        var a = this, t = e.getNetAddresss("plugin.area-dividend.api.area-dividend.getAreaDividend");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 === e.result ? (a.setData({
                    dividend: e.data
                }), console.log(a.data.dividend, "数组")) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    initInfo: function() {
        var a = this, t = e.getNetAddresss("plugin.area-dividend.api.area-dividend.get-area-agent");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 === e.result ? a.setData({
                    level_name: e.data.level_name,
                    rate: e.data.rate,
                    agent_many: e.data.agent_many
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getData: function() {
        var a = this, t = e.getNetAddresss("plugin.area-dividend.api.area-dividend.get-dividend-statistic");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                if (1 === e.result) {
                    var n = {};
                    n.money = e.data.today, n.data = "今日", n.name = "data";
                    var i = [];
                    i.push(n), a.setData({
                        ratioDatas: i
                    });
                    var d = {};
                    d.money = e.data.yesterday, d.data = "昨日", d.name = "data", i.push(d), a.setData({
                        ratioDatas: i
                    });
                    var s = {};
                    s.money = e.data.this_week, s.data = "本周", s.name = "data", i.push(s), a.setData({
                        ratioDatas: i
                    });
                    var o = {};
                    o.money = e.data.this_month, o.data = "本月累计分红", o.name = "mounth", i.push(o), a.setData({
                        ratioDatas: i
                    });
                } else wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getDividendList: function(a) {
        console.log(a);
        var t = e.getNetAddresss("plugin.area-dividend.api.area-dividend.get-dividend-list");
        t += "&status=" + a, t += "&page=" + this.data.page;
        var n = this;
        e._getNetWork({
            url: t,
            success: function(a) {
                var t = a.data;
                if (console.log(t.data.data.data), 1 === t.result) {
                    n.setData({
                        allContent: t.data.data.data
                    });
                    var e = [];
                    t.data.time.forEach(function(a, t) {
                        e.push({
                            create_month: a.create_month,
                            data: [],
                            total: 0,
                            current_page: 1,
                            last_page: 1,
                            is_loading: 0,
                            is_show: 0
                        });
                    }), console.log(e[0], "sssss"), e[0] && (e[0].data = t.data.data.data, e[0].total = t.data.data.total, 
                    e[0].last_page = t.data.data.last_page, e[0].current_page = t.data.data.current_page, 
                    e[0].is_loading = 1, e[0].is_show = 1), console.log(e), n.setData({
                        datas: e
                    }), t.data.data.current_page >= t.data.data.last_page ? n.setData({
                        showNone: !1
                    }) : n.setData({
                        showNone: !0
                    });
                } else wx.showToast({
                    title: t.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getOtherList: function(t) {
        var n = this, i = t.currentTarget.dataset.ind, d = t.currentTarget.dataset.item;
        if (1 == n.data.datas[i].is_show) return n.data.datas[i].is_show = 0, console.log("隐藏数据", n.data.datas), 
        void n.setData({
            datas: n.data.datas
        });
        if (n.data.datas[i].is_show = 1, n.setData({
            datas: n.data.datas
        }), 1 != n.data.datas[i].is_loading) {
            var s = {
                status: n.data.nextStatus ? n.data.nextStatus : "",
                page: 1,
                create_month: d
            }, o = e.getNetAddresss("plugin.area-dividend.api.area-dividend.get-dividend-list");
            e._getNetWork({
                url: o,
                data: s,
                success: function(t) {
                    var e, d = t.data;
                    (console.log(d.data.data.data), 1 === d.result) ? n.setData((a(e = {}, "datas[" + i + "].data", d.data.data.data), 
                    a(e, "datas[" + i + "].total", d.data.data.total), a(e, "datas[" + i + "].last_page", d.data.data.last_page), 
                    a(e, "datas[" + i + "].current_page", d.data.data.current_page), a(e, "datas[" + i + "].is_loading", 1), 
                    a(e, "datas[" + i + "].is_show", 1), e)) : wx.showToast({
                        title: d.msg,
                        icon: "none"
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        } else console.log("已经加载首页数据");
    },
    getNextDividendList: function(t) {
        var n = this, i = t.currentTarget.dataset.item.create_month, d = t.currentTarget.dataset.ind, s = n.data.datas[d].current_page + 1;
        console.log(n.data.datas);
        var o = {
            status: n.data.nextStatus ? n.data.nextStatus : "",
            page: s,
            create_month: i
        }, r = e.getNetAddresss("plugin.area-dividend.api.area-dividend.get-dividend-list");
        e._getNetWork({
            url: r,
            data: o,
            success: function(t) {
                var e, i = t.data;
                (console.log(i.data.data.data), 1 === i.result) ? (n.setData((a(e = {}, "datas[" + d + "].data", n.data.datas[d].data.concat(i.data.data.data)), 
                a(e, "datas[" + d + "].current_page", i.data.data.current_page), e)), console.log(n.data.datas[d])) : wx.showToast({
                    title: i.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    onChange: function(a) {
        console.log(a.detail.index, "555");
        var t = "";
        1 == a.detail.index ? t = "1" : 2 == a.detail.index ? t = "0" : 3 == a.detail.index && (t = "-1"), 
        this.setData({
            nextStatus: t
        }), this.getDividendList(t);
    },
    hideShowPopup: function() {
        this.setData({
            showPopup: !1
        });
    },
    toSelectionarea: function() {
        wx.navigateTo({
            url: "/packageB/member/income/applyRegionalAgency/applyRegionalAgency"
        });
    },
    showPopupTap: function() {
        var a = this;
        wx.showLoading({
            title: "加载中"
        });
        var t = e.getNetAddresss("plugin.area-dividend.api.area-dividend.get-all-area-agent");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                wx.hideLoading({
                    success: function(a) {}
                }), 1 === e.result ? a.setData({
                    showPopup: !0,
                    moreList: e.data
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                wx.hideLoading({
                    success: function(a) {}
                }), console.log(a);
            }
        });
    }
});